import createAxios from '/@/utils/axios'
import { orderStatusEnum } from '/@/views/backend/shop/order/order'
import { auditStatus } from '/@/views/backend/shop/order/refund'
import { routePush } from '/@/utils/router'
import { adminBaseRoutePath } from '/@/router/static/adminBase'

const paths = {
    order: adminBaseRoutePath + '/shop/order/order',
    orderRefund: adminBaseRoutePath + '/shop/order/refund',
    orderExport: adminBaseRoutePath + '/shop/order/export',
    goods: adminBaseRoutePath + '/shop/goods/goods',
}

const notifyApi = adminBaseRoutePath + '/shop.notify.Notify'

export const handleMessage = (id: number | string, message_type: string, data?: any) => {
    switch (message_type) {
        case 'order':
            routePush({
                path: paths.order,
                query: { status: orderStatusEnum.toShipped, order_no: data?.order_no },
            })
            break
        case 'order_cancel':
            routePush({
                path: paths.order,
                query: { status: orderStatusEnum.applyCancel, order_no: data?.order_no },
            })
            break
        case 'order_refund':
            routePush({
                path: paths.orderRefund,
                query: { audit_status: auditStatus.wait_audit, 'orderRelation.order_no': data?.order_no },
            })
            break
        case 'order_export':
            routePush({
                path: paths.orderExport,
                query: { name: data?.name },
            })
            break
        case 'low_stock':
            routePush({
                path: paths.goods,
                query: { name: data?.name },
            })
            break
    }

    return readMessage(id)
}

export const readMessage = (id: number | string | string[]) => {
    return createAxios({
        url: notifyApi + '/read',
        method: 'post',
        data: {
            id,
        },
    })
}
